/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinConfirm.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinConfirmEvent.h"
#include "NetmenuSetupEvent.h"

void SetWinConfirmPalette_1080P(void)
{
    YUVENTRY mask_para[4] = {0,4095,4095,4095};
    AWSetAlphaMask(1,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 15208,0x8000 | 16216,0x8000 | 17880,0x8000 | 16392,16280,16184,16088,16040,16024,15880,15208,15720,15016,15064,15304,15144};
    AWSetPalette(1,16, palette_para);
    return ;
}

INT32S WinConfirmMsg_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
	switch( msg_type){
		case WM_SHOWWINDOW:
			return WinConfirmOnShow(hwnd,lpParam);
		case WM_HIDEWINDOW:
			AWClearRectTxt(hwnd->winrect.left, hwnd->winrect.top, hwnd->winrect.width, hwnd->winrect.height) ;
			return WinConfirmOnHide(hwnd,lpParam);
			
		default:
			break;
	}
	
	return 0;		
}

void SetWinConfirmPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
        default:
            RECT NormalWindowRect = {0,0,1920,1080};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,0,1920,1080},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinConfirmPalette_1080P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinConfirm_1080P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
        default:
            CREATEWINDOWPARAM Normalwindow_para = {1,{{0,0,1920,1080},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinConfirmPalette_1080P};
            //Create Menu Window -- 0
            pNewControl = AWCreateWinControl("TWindow","WinConfirm_1080P",WS_OVERLAPPEDWINDOW,
		                      0,0,1920,1080,NULL, (INT32S)&Normalwindow_para,WinConfirmMsg_1080P) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

// ConfigMessageMsg
INT32S ConfigMessageMsg_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
	switch( msg_type){
		case WM_SHOWWINDOW:
			return 0; 
			
        case WM_KEYDOWN:
        	return ConfigMessageOnKeyPress(hwnd, lpParam);
        	
		case WM_HIDEWINDOW:
			AWClearRectTxt(hwnd->winrect.left, hwnd->winrect.top, hwnd->winrect.width, hwnd->winrect.height) ;
			break;

	}
	
	return 0;		
}

void SetConfigMessagePos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
        default:
            pControl->winrect.top = pControl->parent->winrect.top + 230;
            pControl->winrect.left = pControl->parent->winrect.left + 380;
            pControl->winrect.width = 520;
            pControl->winrect.height = 200;
            pControl->draw_info_num = 5;
            RECT NormalDrawRect[5] = {
			{pControl->winrect.left + 0,pControl->winrect.top + 0,520,200},
			{pControl->winrect.left + 0,pControl->winrect.top + 0,0,0},
			{pControl->winrect.left + 50,pControl->winrect.top + 16,470,30},
			{pControl->winrect.left + 20,pControl->winrect.top + 46,500,30},
			{pControl->winrect.left + 20,pControl->winrect.top + 76,500,30},
            };
            for(iLoop=0; iLoop < 5; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

HWND *CreateControlConfigMessage_1080P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- ConfigMessage
    HWND *pNewControl;
    switch(CurOsdSize){
        default:
            pNewControl = AWCreateWinControl("TControl","ConfigMessage_1080P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      380,230,520,200,pParent,0,ConfigMessageMsg_1080P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 5;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[5] = {
                          {0,0,0,0,(INT32U)ICON_UNSUPPORT_VIDEO_CONFIG,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)NONSUPPORT_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)TIPS1_STR,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)TIPS2_STR,DT_RESOURCE_STRING_DATA},
                          };
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;            
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinConfirm_1080P(void)
{
	
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinConfirm = CreateControlWinConfirm_1080P(NULL,CurrentOsdSize);
    SetWinConfirmPos_1080P(pWinConfirm,CurrentOsdSize);

    pNewControl= CreateControlConfigMessage_1080P(pWinConfirm,CurrentOsdSize);
    SetConfigMessagePos_1080P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinConfirm;
    pWin->pFocusControl = AWFindWinCtrlByName("ConfigMessage_1080P");
    return pWinConfirm;
}

void WinResetWinConfirmControlsPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinConfirm
            SetWinConfirmPos_1080P(pControl,CurOsdSize) ;
            break ;
        case 1://ConfigMessage
            SetConfigMessagePos_1080P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinConfirmPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinConfirm_1080P");
    if(pControl == NULL) return ;

    WinResetWinConfirmControlsPos_1080P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinConfirmPos_1080P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

